package mao.thinkinjava.collection;

import java.util.PriorityQueue;

/**
 * 优先队列接口学习。
 */
public class ToDoList extends PriorityQueue<ToDoList.ToItem> {
    public static class ToItem implements Comparable<ToItem>{
        private int primary;
        private int secondary;
        private String things;
        public ToItem(int primary, int secondary, String things) {
            this.primary = primary;
            this.secondary = secondary;
            this.things = things;
        }

        public String toString(){
            return ""+primary+secondary+":"+things;
        }
        @Override
        public int compareTo(ToItem o) {
            if(primary>o.primary)
                return +1;
            if(primary == o.primary){
                if(secondary>o.secondary)
                    return +1;
                else if(secondary == o.secondary)
                    return 0;
            }
            return -1;
        }


    }

    public static void main(String[] args) {
        ToDoList toDolist = new ToDoList();
        toDolist.add(new ToItem(2,3,"clean room"));
        toDolist.add(new ToItem(1,1,"learning"));
        toDolist.add(new ToItem(1,2,"reading"));

        for (int i = 0; i < 3; i++) {
            ToItem poll = toDolist.poll();
            System.out.println(poll);
        }
    }

}
